package com.newbie.cellsms.action;

import java.sql.SQLException;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.newbie.cellsms.service.DbService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 手动设置
 * 
 * @author Jacarri
 * 
 */
@Results({ @Result(name = "superSettingSuccess", location = "/smsweb.jsp"),
		@Result(name = ActionSupport.INPUT, location = "/smsweb-super.jsp"),
		@Result(name = ActionSupport.SUCCESS, location = "/smsweb.jsp") })
public class SuperSetupAction extends ActionSupport {
	private static final long serialVersionUID = 4388004354634133509L;
	private String columnName;
	private String columnValue;

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public String getColumnValue() {
		return columnValue;
	}

	public void setColumnValue(String columnValue) {
		this.columnValue = columnValue;
	}

	/**
	 * 手动填写key和对应的参数值
	 * 
	 * @return
	 */
	public String superSetting() {
		try {
			DbService.superSetting(columnName, columnValue);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return "superSettingSuccess";
	}

	public String input() {
		return INPUT;
	}

	public void validateSuperSetting() {
		if (null == columnName) {
			this.addFieldError(columnName, "请填写[属性中]的内容");
		} else {
			if (columnName.length() < 1) {
				this.addFieldError(columnName, "请填写[属性中]的内容");
			}
		}
		if (null == columnValue) {
			this.addFieldError(columnValue, "请填写[值]的内容");
		} else {
			if (columnValue.length() < 1) {
				this.addFieldError(columnValue, "请填写[值]的内容");
			}
		}
	}

}
